﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using MiragePWF.Common.Container;
using Wolfut.MirageEE.Domain.Common;
using Wolfut.MirageEE.Domain.CommonUtilities;
using Wolfut.MirageEE.Interface.Common;
using Wolfut.MirageEE.UI.UIBaseComponents;
using Wolfut.MirageEE.UI.UICommonUtilities;
using Wolfut.MirageEE.UI.UI.Common;
using DevExpress.XtraBars;

namespace Wolfut.MirageEE.UI.UIBaseComponents
{
    public partial class UserControlDataDictionary : MirageEEUserControlBase
    {
        public UserControlDataDictionary()
        {
            InitializeComponent();
        }
        private IDataDictionaryService service = null;
        private IList<DataDictionary> listDataDic = null;
        private String _dataDicCate = Constant.DataDictionaryCategory.CUSTOMER_CATE;
        public String DataDicCategory
        {
            get
            {
                return _dataDicCate;
            }
            set
            {
                _dataDicCate = value;
            }
        }
        public String SeletedText
        {
            get
            {
                if (comboBoxDataDic.Properties.Items.Count > 0)
                {
                    return comboBoxDataDic.SelectedText;
                }

                return String.Empty;
            }
            set
            {
                comboBoxDataDic.Text = value;
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            comboBoxDataDic.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);
        }
        protected override void BindGrid(bool IsDBLoading)
        {
            if (IsDBLoading)
            {
                service = IOC.Resolve<IDataDictionaryService>();
                IList<DataDictionary> listDictionary = service.listDataDictionary(false, this.DataDicCategory);
                this.comboBoxDataDic.Properties.Items.Clear();     
                
                if (listDictionary.Count > 0)
                {
                    foreach (DataDictionary item in listDictionary)
                    {
                        this.comboBoxDataDic.Properties.Items.Add(item.Remarks);
                    }
                }
                this.comboBoxDataDic.Properties.Items.Add("新增");
                this.comboBoxDataDic.SelectedIndex = 0;                
            }
        }
        private void ComboBox_SelectedIndexChanged(Object sender,EventArgs e)
        {
            if (comboBoxDataDic.SelectedItem.ToString().Contains("新增"))
            {
                ProjectForm form = IOC.Resolve<ProjectForm>("ProjectForm") as ProjectForm;
                form.ShowDialog();
            }
        }
    }
}
